home *** CD-ROM | disk | FTP | other *** search
- Path: EU.net!sun4nl!xs4all!usenet
- From: martijnl@xs4all.nl (Martijn Lievaart)
- Newsgroups: comp.lang.c,comp.lang.c++
- Subject: Re: -> How do you use the EXTERN keyword? <-
- Date: 7 Jan 1996 01:27:35 GMT
- Organization: XS4ALL, networking for the masses
- Message-ID: <4cn7i7$he7@news.xs4all.nl>
- References: <4chkq2$1s06@pulp.ucs.ualberta.ca> <30EC9149.6807@holli.com>
- NNTP-Posting-Host: mas01-09.dial.xs4all.nl
- X-Newsreader: WinVN 0.99.6
-
- In article <30EC9149.6807@holli.com>, gotwals@holli.com says...
- >
- >Jacob Bukczynski wrote:
- >>
- >> I need to use variables in two different source files in the
- >> same project. I know that you need to declare them somehow
- >> with the EXTERN keyword but I don't know how.
- >>
- >> Please help! Reply by email if possible, or just follow-up
- >> here. Thanks in advance.
- >
- >Here is a simple example:
- >
- >// sample1.cpp
- >int globalVar = 123;
- >
- >// define your function(s) here
- >
- >// end of file
- >
- >// sample2.cpp
- >extern int globalVar;
- >
- >// define some more functions here
- >
- >// end of file
- >
- >
-
- Why not in a header? OK, the linker will catch any errors but it is poor
- style. Next time you work on a C project, this style will come back to haunt
- you.
-
- > I am concerned with the truth. Reality is of little interest to me.
-
- That's obvious now.
-
-